$.fn.appelDynamique = function(data,url,container) {
	var $this = $(this),
	$data={"none":0},
	$file="receptionAjax",
	$container="modal";
	function init() {
		callDaAjax();
	}
	function callDaAjax() {
		$.ajax({
			type: "POST",
			url: url,
			data: data,
			dataType: "json",
			encode:true,
			async:   true
		}).done(function( retour ) {
			showMe(retour);
		});
	}
	function showMe(retour) {
		if(container==""||container==undefined){
			table=$(retour.data).addClass("modaltable");
			bootbox.alert(utf8_decode(table.outerHTML()));
			$(".modaltable").paginationcustom();
			listenerDetails();
		}
		if(container=="notify"){
			$("body").prepend('<div class="alert alert-success fade in"><a href="#" class="close" data-dismiss="alert">&times;</a>'+utf8_decode(retour.data)+'</div>');
			setInterval(function () {$(".alert").alert('close');}, 5000);
		}
	}
	init();
};
$(document).ready(function(){
	$("#tkassigne").click( function(){
		$(this).appelDynamique({"type":"tkassignes"},"./retourAjax/receptionAjax.php");
	});
	$("#tknonassigne").click( function(){
		$(this).appelDynamique({"type":"tkattente"},"./retourAjax/receptionAjax.php");
	});
	$("#tk_express").click( function(){
		$(this).appelDynamique({"type":"tk_express"},"./retourAjax/receptionAjax.php");
		$("input[name='ajout_ticket'").unbind('click');
		$(document).unbind('ajaxStop');
		$(document).ajaxStop(function () {
			$(document).unbind('ajaxStop');
			if($("input[name='ajout_ticket']").length){
				$("input[name='ajout_ticket'").attr("type","button");
				$('[data-bb-handler="ok"]').text("Annuler")
				console.log($("input[name='ajout_ticket'").attr("type"));
				$("input[name='ajout_ticket'").click(function(){
					$("[name='form_ajout']").ajaxSubmit({url: './retourAjax/receptionAjax.php', 
						type: 'post', 
						success:  function(responseText) { 
							 retour=JSON.parse(responseText);
							 if(retour.data!="nein"){
								 $("body").prepend('<div class="alert alert-success fade in"><a href="#" class="close" data-dismiss="alert">&times;</a><strong>'+utf8_decode(retour.data)+'</div>');
								setInterval(function () {$(".alert").alert('close');}, 5000);
								bootbox.hideAll();
							 }else{
								 $(".modaltable").prepend("<strong>Merci de bien vouloir remplir TOUTES les informations!");
							 }
						} 
					});
				});
			}
		});
	});
});